'''
n双相异的鞋共2n只，随机地分配成n堆，每堆2只。问“各堆都自成一双鞋”这个事件E地概率是多少

提示：n个相异物件分成k堆，各堆物件数分别为r1,...,rk的分法： n! / (r1!...rk!)
'''

from scipy.special import comb, perm, factorial
import math
import numpy as np

# 假设
n = 3
expect_result = factorial(n) / (factorial(2 * n) / math.pow(2, n))

result = np.random.choice(2 * n, [n, 2], replace=False)

cycle_count = 10000
count = 0
sign = False
for i in range(cycle_count):
    for j in range(n):
        item = np.random.choice(2 * n, [1, 2], replace=False)
        if item.flatten() not in result:
            sign = False
            break
        sign = True
    if sign:
        count += 1
print(count)
actual_result = count / cycle_count
print(f"acutal:{actual_result},expect:{expect_result}")
